/////////////////////////////////////////////////////////////////////////////
// Name:        dgt_SyntezDialog.cpp
// Purpose:     
// Author:      Aleksey Plotnikov & Alla Nabatova
// Modified by: 
// Created:     20/05/2008 19:10:11
// RCS-ID:      
// Copyright:   Diamant Software
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dgt_SyntezDialog.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "dgt_SyntezDialog.h"
#include "dgt_StudioApp.h"
#include "dgt_PluginManager.h"
#include "dgt_TriggerElement.h"

////@begin XPM images
////@end XPM images


/*!
 * dgt_SyntezDialog type definition
 */

IMPLEMENT_DYNAMIC_CLASS( dgt_SyntezDialog, wxDialog )


/*!
 * dgt_SyntezDialog event table definition
 */

BEGIN_EVENT_TABLE( dgt_SyntezDialog, wxDialog )

////@begin dgt_SyntezDialog event table entries
////@end dgt_SyntezDialog event table entries

END_EVENT_TABLE()


/*!
 * dgt_SyntezDialog constructors
 */

dgt_SyntezDialog::dgt_SyntezDialog()
{
    Init();
}

dgt_SyntezDialog::dgt_SyntezDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}


/*!
 * dgt_SyntezDialog creator
 */

bool dgt_SyntezDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin dgt_SyntezDialog creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end dgt_SyntezDialog creation
    return true;
}


/*!
 * dgt_SyntezDialog destructor
 */

dgt_SyntezDialog::~dgt_SyntezDialog()
{
////@begin dgt_SyntezDialog destruction
////@end dgt_SyntezDialog destruction
}


/*!
 * Member initialisation
 */

void dgt_SyntezDialog::Init()
{
////@begin dgt_SyntezDialog member initialisation
    m_ChoiceCA = NULL;
    m_TriggerCA = NULL;
    m_ChoiceOA = NULL;
    m_OutPlug = NULL;
////@end dgt_SyntezDialog member initialisation
}


/*!
 * Control creation for dgt_SyntezDialog
 */

void dgt_SyntezDialog::CreateControls()
{    
////@begin dgt_SyntezDialog content construction
    dgt_SyntezDialog* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);

    wxAuiNotebook* itemAuiNotebook4 = new wxAuiNotebook( itemDialog1, ID_SYNTEZNOTEBOOK, wxDefaultPosition, wxSize(400, 300), 0 );

    wxPanel* itemPanel5 = new wxPanel( itemAuiNotebook4, ID_CONTROLPANEL, wxDefaultPosition, wxSize(400, 300), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
    itemPanel5->SetSizer(itemBoxSizer6);

    wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer6->Add(itemBoxSizer7, 0, wxGROW|wxALL, 5);
    wxStaticText* itemStaticText8 = new wxStaticText( itemPanel5, wxID_STATIC, _("Architecture plugin"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer7->Add(itemStaticText8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString m_ChoiceCAStrings;
    m_ChoiceCA = new wxChoice( itemPanel5, ID_ARCHCA, wxDefaultPosition, wxDefaultSize, m_ChoiceCAStrings, 0 );
    itemBoxSizer7->Add(m_ChoiceCA, 1, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer6->Add(itemBoxSizer10, 0, wxGROW|wxALL, 5);
    wxStaticText* itemStaticText11 = new wxStaticText( itemPanel5, wxID_STATIC, _("Triggers"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer10->Add(itemStaticText11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString m_TriggerCAStrings;
    m_TriggerCA = new wxChoice( itemPanel5, ID_TRIGCA, wxDefaultPosition, wxDefaultSize, m_TriggerCAStrings, 0 );
    itemBoxSizer10->Add(m_TriggerCA, 1, wxGROW|wxALL, 5);

    itemAuiNotebook4->AddPage(itemPanel5, _("Control Automat"), false);

    wxPanel* itemPanel13 = new wxPanel( itemAuiNotebook4, ID_OPERPANEL, wxDefaultPosition, wxSize(400, 300), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL);
    itemPanel13->SetSizer(itemBoxSizer14);

    wxBoxSizer* itemBoxSizer15 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer14->Add(itemBoxSizer15, 0, wxGROW|wxALL, 5);
    wxStaticText* itemStaticText16 = new wxStaticText( itemPanel13, wxID_STATIC, _("Architecture plugin"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer15->Add(itemStaticText16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString m_ChoiceOAStrings;
    m_ChoiceOA = new wxChoice( itemPanel13, ID_ARCHOA, wxDefaultPosition, wxDefaultSize, m_ChoiceOAStrings, 0 );
    itemBoxSizer15->Add(m_ChoiceOA, 1, wxGROW|wxALL, 5);

    itemAuiNotebook4->AddPage(itemPanel13, _("Operation Automat"), false);

    itemBoxSizer3->Add(itemAuiNotebook4, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 5);

    wxBoxSizer* itemBoxSizer18 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer18, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText19 = new wxStaticText( itemDialog1, wxID_STATIC, _("Output Plugin"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer18->Add(itemStaticText19, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString m_OutPlugStrings;
    m_OutPlug = new wxChoice( itemDialog1, ID_OUTPLUG, wxDefaultPosition, wxDefaultSize, m_OutPlugStrings, 0 );
    itemBoxSizer18->Add(m_OutPlug, 1, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer21, 0, wxALIGN_RIGHT|wxALL, 5);

    wxButton* itemButton22 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer21->Add(itemButton22, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxButton* itemButton23 = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer21->Add(itemButton23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

////@end dgt_SyntezDialog content construction

	dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
	dgt_PluginManager *pManager = tApp->get_Manager();


	// TODO: there must be checking for ability of syntez - checking of syntez plugins and logical, and triggers

	/// Initializing choices

	// choice for select plugin of syntez Control Automat
	unsigned cCount = pManager->get_PluginCount( PLUGIN_SYNTEZ_CA );

	for( unsigned i = 0 ; i<cCount; i++ )
	{
		dgt_Plugin_Ptr pPlugin = pManager->get_Plugin( PLUGIN_SYNTEZ_CA, i );

		if( pPlugin.get() )
		{
			dgt_PluginInfo tInfo;
			pPlugin->GetPluginInfo( tInfo );

			m_ChoiceCA->AppendString( tInfo.m_PluginName );
		}
	}	

	cCount = pManager->get_PluginCount( PLUGIN_SYNTEZ_OA );

	for( unsigned i = 0 ; i<cCount; i++ )
	{
		dgt_Plugin_Ptr pPlugin = pManager->get_Plugin( PLUGIN_SYNTEZ_OA, i );

		if( pPlugin.get() )
		{
			dgt_PluginInfo tInfo;
			pPlugin->GetPluginInfo( tInfo );

			m_ChoiceOA->AppendString( tInfo.m_PluginName );
		}
	}

	// choice for select triggers in control automat
	unsigned tCount = pManager->get_PluginCount( PLUGIN_TRIGGER );

	for( unsigned i = 0; i<tCount; i++ )
	{
		dgt_Plugin_Ptr pPlugin = pManager->get_Plugin( PLUGIN_TRIGGER, i );

		if( pPlugin.get() )
		{
			unsigned long eCount = pPlugin->get_ElementCount();

			for( int j = 0; j < eCount; j++ )
			{
				dgt_Element_Ptr pElement = pPlugin->get_Element( j );

				m_TriggerCA->AppendString( pElement->get_Name() );
			}
		}
	}

	// choice for select output plugin
	tCount = pManager->get_PluginCount( PLUGIN_OUT );

	for( unsigned i = 0; i<tCount; i++ )
	{
		dgt_Plugin_Ptr pPlugin = pManager->get_Plugin( PLUGIN_OUT, i );

		if( pPlugin.get() )
		{
			dgt_PluginInfo tInfo;

			pPlugin->GetPluginInfo( tInfo );
			wxString name = tInfo.m_PluginName;
			m_OutPlug->AppendString( name );
		}
	}

	m_OutPlug->SetSelection( 0 );
	m_TriggerCA->SetSelection( 0 );
	m_ChoiceCA->SetSelection( 0 );
	m_ChoiceOA->SetSelection( 0 );
}


/*!
 * Should we show tooltips?
 */

bool dgt_SyntezDialog::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap dgt_SyntezDialog::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin dgt_SyntezDialog bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end dgt_SyntezDialog bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon dgt_SyntezDialog::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin dgt_SyntezDialog icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end dgt_SyntezDialog icon retrieval
}


unsigned	dgt_SyntezDialog::get_CAPlugCode( void )
{
	return m_ChoiceCA->GetSelection();
}

unsigned	dgt_SyntezDialog::get_OAPlugCode( void )
{
	return m_ChoiceOA->GetSelection();;
}

unsigned	dgt_SyntezDialog::ger_TrigCode( void )
{
	return m_TriggerCA->GetSelection();
}
